package com.zqxq.lottery.controller.jczq;

import com.zqxq.common.bo.RequestHeaderBO;
import com.zqxq.common.constant.Result;
import com.zqxq.common.enums.CodeEnum;
import com.zqxq.lottery.entity.bo.jczq.MatchApiBO;
import com.zqxq.lottery.entity.po.jczq.JczqMatchPO;
import com.zqxq.lottery.entity.vo.jczq.*;
import com.zqxq.lottery.service.jczq.IJczqMatchService;
import com.zqxq.lottery.service.sys.ISysAppVersionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 说    明：   竞猜足球--赛事信息
 * 创 建 人：	一刀·胡
 * 创建时间：	2018/5/9 18:24
 * 修 改 人：
 * 修改日期：
 **/
@RestController
@Slf4j
public class JczqMatchController extends JczqBaseController {

    @Autowired
    private IJczqMatchService jczqMatchService;
    @Autowired
    private ISysAppVersionService sysAppVersionService;

    @PostMapping("/jczqMatch/get")
    public Result getJczqMatchById(String id){
        Result rs = new Result();
        try{
            JczqMatchVO vo = jczqMatchService.get(id);
            rs.setData(vo);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("get JczqMatchById  Error:",e);
        }
        return rs;
    }

    @PostMapping("/jczqMatch/getByCode")
    public Result getJczqMatchByCode(@RequestParam String code){
        Result rs = new Result();
        try{
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            JczqMatchPO po = jczqMatchService.getByCode(code);
            if (po != null) {
                rs.setCode(CodeEnum.SUCCESS.getCode());
                rs.setMsg(CodeEnum.SUCCESS.getMsg());
                rs.setData(po);
            }
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("get getJczqMatchByCode  Error:",e);
        }
        return rs;
    }

    @PostMapping("/match/hot/list")
    public Result queryHotMatchList(@RequestBody MatchApiBO search){
        Result rs = new Result();
        try{
            List<MatchApiVO1> list =  jczqMatchService.queryHotMatchList(search);
            rs.setData(list);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("Query hotMatchList Error:",e);
        }
        return rs;
    }
    //焦点赛事
    @PostMapping("/home/hot/list")
    public Result homeHotMatchList(){
        Result rs = new Result();
        try{
            List<HomeMatchVO> list =  jczqMatchService.queryHomeHotMatchList();
            rs.setData(list);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("Query homeHotMatchList Error:",e);
        }
        return rs;
    }

    //热门赛事
    @PostMapping("/home/hot/list2")
    public Result homeHotMatchList2(){
        Result rs = new Result();
        try{
            List<HomeMatchVO> list =  jczqMatchService.queryHomeHotMatchList2();
            rs.setData(list);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("Query homeHotMatchList2 Error:",e);
        }
        return rs;
    }

    @PostMapping("/app/switch/activity")
    public Result<?> queryWhichActivity(@RequestBody RequestHeaderBO search){
        Result rs = new Result();
        try{
            rs.setData(jczqMatchService.queryWhichActivity());
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("QueryWorldCupList Error:",e);
        }
        return rs;
    }

    @PostMapping("/league/hot/list")
    public Result hotLeagueList(){
        Result rs = new Result();
        try{
            List<LeagueApiVO> list =  jczqMatchService.queryHotLeagueList();
            rs.setData(list);
        }catch(Exception e){
            rs.setCode(CodeEnum.FAIL.getCode());
            rs.setMsg(CodeEnum.FAIL.getMsg());
            log.error("Query hotLeagueList Error:",e);
        }
        return rs;
    }

    @PostMapping("/channel/count")
    public Result downloadChannelCount(String channel, String downSource){
        return sysAppVersionService.saveChannelCount(channel,downSource);
    }
}
